package com.edu.chapter07;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.media3.common.MediaItem;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.ui.PlayerView;


public class ExoplayerActivity extends AppCompatActivity {
    private final String URL = "https://vfx.mtime.cn/Video/2021/07/10/mp4/210710122716702150.mp4";
    private ExoPlayer player;
    private PlayerView playerView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exoplayer);

        player = new ExoPlayer.Builder(this).build();
        playerView = findViewById(R.id.player_view);
        playerView.setPlayer(player);

        MediaItem mediaItem = MediaItem.fromUri(URL);
        player.setMediaItem(mediaItem);

    }

    @Override
    protected void onStart() {
        super.onStart();
        player.prepare();
        player.play();
    }

    @Override
    protected void onStop() {
        super.onStop();
        player.stop();
        player.release();
    }
}